package com.tsyun.view_project.list.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.makeramen.roundedimageview.RoundedImageView;
import com.tsyun.view_project.R;
import com.tsyun.view_project.list.bean.DynamicBean;

import java.util.ArrayList;
import java.util.List;

public class SampleAdapter extends BaseAdapter {
    //列表显示的条目的数量
    private List<DynamicBean> beans;
    private Context context;
    public SampleAdapter(Context context,List<DynamicBean> beans) {
        this.context  = context;
        this.beans = beans;
//        this.beans = new ArrayList<>();

    }

    private static final int HEADER = 1;
    private static final int NORMAL = 2;
    @Override
    public int getItemViewType(int position) {
        return position/2==0?HEADER:NORMAL;
    }

    public void setBeans(List<DynamicBean> beans) {
        this.beans = beans;
    }

    @Override
    public int getCount() {
        return beans.size();
    }

    //获取每一个对象的实例
    @Override
    public Object getItem(int position) {
        return null;
    }

    //每一项的ID
    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //LayoutInflater 布局加载器
        int viewType = getItemViewType(position);

        View itemView = LayoutInflater.from(context).inflate(R.layout.item_sample,parent,false);
        TextView tvName = itemView.findViewById(R.id.tv_name);
        RoundedImageView ivHead = itemView.findViewById(R.id.iv_head);
        TextView tvDate = itemView.findViewById(R.id.tv_date);
        TextView tvContent = itemView.findViewById(R.id.tv_content);
        DynamicBean db = beans.get(position);
        //给项目中的每一项赋值
        tvName.setText(db.getName());
        Glide.with(context).load(db.getHeadPic()).into(ivHead);
        tvDate.setText(db.getDate());
        tvContent.setText(db.getContent());
        return itemView;
    }
}
